package com.zhixi.controller;

import com.zhixi.pojo.User;
import com.zhixi.service.UserService;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName UserController
 * @Author zhangzhixi
 * @Description
 * @Date 2022-5-1 12:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 日志
     */
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Resource
    private UserService userService;

    @RequestMapping("/getUserById/{id}")
    public User getUserById(@PathVariable("id") Long id) {
        User user = new User();
        User queryUser = userService.selectByIdUser(id);
        if (queryUser != null) {
            user = queryUser;
        }
        return user;
    }

    @PostMapping("/updateUser")
    public String updatetUser(@RequestBody User user) {
        return userService.updateUser(user) != null ? "更新成功" : "更新失败";
    }

    @PostMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable("id") Long id) {
        return userService.delUser(id) ? "删除成功" : "删除失败";
    }
}



